import axios from "axios";
let instance = axios.create({
  // baseURL: "http://kumanxuan1.f3322.net:8881/cms", //基本网址
  baseURL: "http://520it.com:8881/cms",
  timeout: 5000,
});
// 请求拦截器
instance.interceptors.request.use(
  (config) => {
    console.log("请求之前拦截。。。1");
    //在这里统一设置请求头 配置token
    if (config.url === "/sendSMS") {
      config.headers["Content-type"] = "application/x-www-form-urlencoded";
    }
    //配置token
    let mytoken = localStorage.getItem("x-auth-token");
    if (mytoken) {
      config.headers["x-auth-token"] = mytoken;
    }
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);
//拦截器
instance.interceptors.response.use(
  (res) => {
    console.log("响应之前拦截。。。2");
    if (res.data.code != 0 && res.data.code != 400 && res.data.code != 407) {
      alert(res.data.message);
      return false;
    }
    return res.data;
  },
  (err) => {
    return Promise.reject(err);
  }
);

export default instance;
